package cn.iocoder.yudao.module.peizhen.controller.app.hospital;

import cn.iocoder.yudao.module.peizhen.dal.dataobject.hospital.SectionDO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.module.peizhen.controller.app.hospital.vo.*;
import cn.iocoder.yudao.module.peizhen.dal.dataobject.hospital.HospitalDO;
import cn.iocoder.yudao.module.peizhen.service.hospital.HospitalService;

@Tag(name = "用户 APP - 医院")
@RestController
@RequestMapping("/peizhen/hospital")
@Validated
public class AppHospitalController {

    @Resource
    private HospitalService hospitalService;




    @GetMapping("/get")
    @Operation(summary = "获得医院")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppHospitalRespVO> getHospital(@RequestParam("id") Integer id) {
        HospitalDO hospital = hospitalService.getHospital(id);
        return success(BeanUtils.toBean(hospital, AppHospitalRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得医院分页")
    public CommonResult<PageResult<AppHospitalRespVO>> getHospitalPage(@Valid AppHospitalPageReqVO pageReqVO) {
        PageResult<HospitalDO> pageResult = hospitalService.getHospitalPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppHospitalRespVO.class));
    }


    // ==================== 子表（医院科室） ====================

    @GetMapping("/section/page")
    @Operation(summary = "获得医院科室分页")
    @Parameter(name = "hospitalId", description = "医院id")
    public CommonResult<PageResult<SectionDO>> getSectionPage(PageParam pageReqVO,
                                                              @RequestParam("hospitalId") Integer hospitalId) {
        return success(hospitalService.getSectionPage(pageReqVO, hospitalId));
    }




	@GetMapping("/section/get")
	@Operation(summary = "获得医院科室")
	@Parameter(name = "id", description = "编号", required = true)
	public CommonResult<SectionDO> getSection(@RequestParam("id") Integer id) {
	    return success(hospitalService.getSection(id));
	}

}